var cfg = require('cfg');
const { $Toast } = require('../dist/base/index');

var sendReq = function (url, params, successCallBack, completeCallBack, errorCallBack) {
  wx.request({
    url: cfg.host + url,
    data: params,
    success: function (res) {
      console.log(res.data);
      if (res.data.code !== 1000) {
        wx.showToast({
          title: res.data.message,
          icon: 'none',
          duration: 3000
        })

        if (errorCallBack) {
          errorCallBack();
        }
        return;
      }

      successCallBack(res.data);
    },
    complete: function () {
      if (completeCallBack) {
        completeCallBack();
      }
    },
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    method: 'POST'
  })
}

module.exports = {
  sendReq
}